package com.schooleducation.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.schooleducation.entity.Lesson;
import com.schooleducation.entity.LessonContent;
import com.schooleducation.entity.User;
import com.schooleducation.service.ServiceFactory;

@Controller
@RequestMapping("/userCenter")
public class UserCenterController {

	@Resource(name = "serviceFac")
	private ServiceFactory serviceFac;
	
	/**
	 * 获取个人中心页面
	 * @param session
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String getUserCenterPage(HttpSession session, Model model) {
		User user = (User) session.getAttribute("user");
		if (user != null) {
			List<Lesson> ls = this.serviceFac.getLessonService().getNewLessonList(0, 6);
			List<LessonContent> nlcs = this.serviceFac.getLessonService().getNewLessonContentList(0, 10);
			
			model.addAttribute("user", user);
			model.addAttribute("lesson", ls);
			model.addAttribute("newContent", nlcs);
			
			return "userCenter";
		} else {
			return "redirect:login";
		}
	}
}
